package com.example.fragments;

import java.util.HashMap;
import java.util.Map;

import com.example.livingplace.*;
import com.example.smarthomecontroller.R;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import android.widget.TextView;

public class RoomFragment extends Fragment {
	Switch s1;
	static String raum; 
	
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
	
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		 Log.d("CREATE", "---- REGISTRIERT");
	 	 View view = inflater.inflate(R.layout.room_fragment, container, false); 
		 s1 = (Switch) view.findViewById(R.id.licht1);
         s1.setOnCheckedChangeListener(s1Listener);
         
         TextView roomText = (TextView) view.findViewById(R.id.text1);
         roomText.setText("Licht des Raums: "+raum);
		 return view;

	 }

	 public void setText(String item) {
		 TextView view = (TextView) getView().findViewById(R.id.text1);
		 view.setText(item);
	 }

	 OnCheckedChangeListener s1Listener = new OnCheckedChangeListener() {
		 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if(isChecked == true){
		            Map<String,String> valueMap = new HashMap<String, String>();
		            valueMap.put("fadeTime","0");
		            new SendMessageToProxy().execute(JSONHelper.createMessage("LP.LIGHTCONTROL", raum+"_light_on" , valueMap));
		        }else{
		            Map<String,String> valueMap = new HashMap<String, String>();
		            valueMap.put("fadeTime","0");
		            new SendMessageToProxy().execute(JSONHelper.createMessage("LP.LIGHTCONTROL", raum+"_light_off" , valueMap));
		        }	
		}
	};
	
	 

}
